home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FUZZY.ZIP / DATA_DEF.S < prev    next >
Text File  |  1986-11-30  |  9KB  |  214 lines

  1. -------------------------------------------------------------------------------
  2. --                                                                           --
  3. --  Library Unit:  Data_def -- Common data type definitions                  --
  4. --                                                                           --
  5. --  Author:  Bradley L. Richards                                             --
  6. --                                                                           --
  7. --     Version     Date     Notes . . .                                      --
  8. --    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    --
  9. --       1.0    19 Jun 86   Initial Version (broken out from Token)          --
  10. --       2.0    20 Jun 86   Extracted token_type from Token as well          --
  11. --       2.1    21 Jul 86   Demonstration Version                            --
  12. --       2.3    19 Aug 86   Combine strings and identifiers                  --
  13. --       3.0    10 Oct 86   Final thesis product                             --
  14. --    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    --
  15. --                                                                           --
  16. --  Library units used:  none                                                --
  17. --                                                                           --
  18. -------------------------------------------------------------------------------
  19. --                                                                           --
  20. --                           Package Specification                           --
  21. --                                                                           --
  22. -------------------------------------------------------------------------------
  23.  
  24. package data_def is
  25.  
  26.  
  27.     --
  28.     --  define special types required for identifier and string tokens
  29.     --
  30.  
  31.     type name_record(size : positive := 1) is       -- minimum of one character
  32.       record
  33.     name : string(1..size);
  34.       end record;
  35.     type name_ptr is access name_record;
  36.  
  37.     --
  38.     --  This type defines all tokens which may be encountered in a Fuzzy
  39.     --  Prolog source program.  The tokens which represent reserved words
  40.     --  (RW_xxx) only occur as elements under type "reserved_word."  The
  41.     --  grouping of these tokens is required to allow subtypes to be defined
  42.     --  (see below)
  43.     --
  44.     type token_type is (character_lit, end_of_file, float_num, identifier,
  45.             integer_num, null_token, reserved_word, variable,
  46.             --
  47.             -- special tokens
  48.             --
  49.             implication, left_bracket, left_paren, period,
  50.             right_bracket, right_paren, underline,
  51.             --
  52.             -- binary operators
  53.             --
  54.             bar, comma, hat, semicolon,
  55.             asterisk, minus, plus, slash, rw_mod,
  56.             equal, equality, greater_or_equal, greater_than,
  57.             less_or_equal, less_than, not_equal, not_equality,
  58.             univ, rw_is,
  59.             --
  60.             -- unary operators
  61.             --
  62.             rw_nospy, rw_not, rw_spy,
  63.  
  64.             --
  65.             -- reserved predicates
  66.             --
  67.             cut, 
  68.             rw_asserta, rw_assertz, rw_atom, rw_atomic, rw_call,
  69.             rw_clause, rw_consult, rw_debugging, rw_display,
  70.             rw_fail, rw_float, rw_functor, rw_fuzzy, rw_get,
  71.             rw_get0, rw_integer, rw_listing, rw_ln, rw_log,
  72.             rw_name, rw_nl, rw_nodebug, rw_nonvar, rw_notrace,
  73.             rw_number, rw_op, rw_org, rw_parse, rw_put, rw_read,
  74.             rw_repeat, rw_reset, rw_retract, rw_see, rw_seeing,
  75.             rw_seen, rw_skip, rw_tab, rw_tell, rw_telling,
  76.             rw_threshold, rw_told, rw_trace, rw_true, rw_user,
  77.             rw_var, rw_write);
  78.  
  79.     subtype operators is token_type range bar..rw_spy;
  80.     subtype binary_operators is token_type range bar..rw_is;
  81.     subtype binary_logic_operators is token_type range bar..semicolon;
  82.     subtype unary_operators is token_type range rw_nospy..rw_spy;
  83.     subtype reserved_predicates is token_type range cut..rw_write;
  84.  
  85.     --
  86.     --  Define the range of fuzzy values
  87.     --
  88.     subtype fuzzy_values is float range 0.0..1.0;
  89.  
  90.     --
  91.     --  These declarations must be interlaced because of their mutual
  92.     --  dependencies.  They could be clarified somewhat by more use of
  93.     --  multilevel variant records.  Unfortunately, Dave Craine has shown
  94.     --  that multilevel variants which contain pointers are not handled
  95.     --  correctly by the Verdix compiler.
  96.     --
  97.     --  ident_data is a variant record which holds data corresponding to
  98.     --  the type of the identifier.
  99.     --
  100.     --  Abstract Syntax Trees are built up out of operator nodes and leaf
  101.     --  nodes.  These are all variant types of type AST.
  102.     --
  103.  
  104.     --
  105.     --  define the types of things that can appear as arguments to predicates
  106.     --
  107.     type argument_type is (character_lit, float_num, integer_num, predicate,
  108.                prolog_list, variable);
  109.     --
  110.     --  A couple of forward references
  111.     --
  112.     type p_list(has_tail : boolean);
  113.     type p_list_ptr is access p_list;
  114.     --
  115.     --     Arguments are defined as a linked list of variant records.  The
  116.     --  representation of a Prolog list also uses these definitions, since
  117.     --  the requirements are essentially identical.
  118.     --
  119.     type argument(is_a : argument_type);
  120.     type argument_ptr is access argument;
  121.     type argument(is_a : argument_type) is
  122.       record
  123.     next_arg : argument_ptr := null;
  124.     case is_a is
  125.       when character_lit  =>  char : character := ' ';
  126.       when float_num      =>  fp_num : float := 0.0;
  127.       when integer_num    =>  int_num : integer := 0;
  128.       when predicate      =>  name : name_ptr := null;
  129.                   p_arguments : argument_ptr := null;
  130.       when prolog_list    =>  list : p_list_ptr := null;
  131.       when variable       =>  v_name : name_ptr := null;
  132.     end case;
  133.       end record;
  134.  
  135.     --
  136.     --     Now we need to define the representation of a Fuzzy Prolog list.
  137.     --     We'll leach off of the argument types, since they're what we need.
  138.     --
  139.     --        for example:     [ a, b | X ]
  140.     --
  141.     type p_list(has_tail : boolean) is
  142.       record
  143.     elt : argument_ptr := null;
  144.     case has_tail is
  145.         when false  =>  next_elt : p_list_ptr := null;
  146.         when true   =>  tail : argument_ptr := null;
  147.       end case;
  148.       end record;
  149.  
  150.     --
  151.     --     Now to define the type of nodes we can have in our Abstract Syntax
  152.     --  Tree (AST).  These fall into two main categories:  interior nodes and
  153.     --  leaf nodes.  All interior nodes represent operators of one variety or
  154.     --  another; "implication" also links the clauses in the
  155.     --  data base together.  Similarly, leaf nodes generally represent operands.
  156.     --  There are a few which are a bit different; for example, it may not be
  157.     --  obvious at first glance that the "cut" is an operand, as are all calls
  158.     --  to predicates.
  159.     --
  160.     type AST_node_type is (implication, binary_operator, unary_operator,
  161.                predicate, integer_num, float_num, character_lit, fuzzy_value,
  162.            reserved_predicate, variable, resolution_marker,
  163.            threshold_marker);
  164.     type AST(node_type : AST_node_type);
  165.     type AST_ptr is access AST;
  166.     type AST(node_type : AST_node_type) is
  167.       record
  168.     case node_type is
  169.       --
  170.       --  interior nodes
  171.       --
  172.       when implication         =>  head, tail : AST_ptr := null;
  173.                        prev, next : AST_ptr := null;
  174.       when binary_operator     =>  binary_op : binary_operators;
  175.                        left_operand : AST_ptr := null;
  176.                        right_operand : AST_ptr := null;
  177.       when unary_operator      =>  unary_op : unary_operators;
  178.                        operand : AST_ptr := null;
  179.       --
  180.       --  leaf nodes
  181.       --
  182.       when predicate           =>  name : name_ptr := null;
  183.                        p_arguments : argument_ptr := null;
  184.       when integer_num         =>  int_num : integer := 0;
  185.       when float_num           =>  fp_num : float := 0.0;
  186.       when character_lit       =>  char : character := ascii.nul;
  187.       when fuzzy_value         =>  fuzzy_num : fuzzy_values := 0.0;
  188.       when reserved_predicate  =>  predicate : reserved_predicates;
  189.                        r_arguments : argument_ptr := null;
  190.       when variable            =>  var_name : name_ptr;
  191.       --
  192.       --  interior nodes used only in Prover goal trees
  193.       --
  194.       when resolution_marker   =>  level : natural;
  195.                        old_threshold : fuzzy_values;
  196.                        subgoals : AST_ptr;
  197.       when threshold_marker    =>  fuzzy_value : fuzzy_values;
  198.                         threshold : fuzzy_values;
  199.     end case;
  200.       end record;
  201.  
  202.     type binding;
  203.     type binding_list is access binding;
  204.     type binding is
  205.       record
  206.     name : name_ptr;
  207.     level : natural;
  208.     value : argument_ptr;
  209.     value_level : natural;
  210.     next_binding : binding_list;
  211.       end record;
  212.  
  213. end data_def;
  214.